#include <sys/socket.h>
#include "unp.h"
#include "globals.h"


int msg_send (int sockfd, char *dest_addr, int dest_port, 
				char *buff, int force_route_dis) 
{
	struct sockaddr_un sockaddr;
	message  req_message;
	int n;
	char message[MAXLINE];
	strcpy(message, "Test");
	bzero(&sockaddr, sizeof(sockaddr));
	sockaddr.sun_family = AF_LOCAL;
	strcpy(sockaddr.sun_path, CUSTOM_SUN_PATH);
	strncpy(req_message.destip, dest_addr, IPSIZE);
	printf("destip %s\n", req_message.destip);
	//mesg.dest_port = dest_port;
	//memset(mesg.msg, '\0', 50);
	//strncpy(mesg.msg, buff, 50);
	//mesg.force_route_dis = force_route_dis;
	printf("before sendto\n");
	n = sendto(sockfd, &req_message, sizeof(req_message), 0, (SA *)&sockaddr, sizeof(struct sockaddr_un));
	printf("Send Result %d", n);
	return(0);
}

int msg_recv (int sockfd, char *msg_recvd, char *src_addr, int *src_port)
{
	struct sockaddr_un sockaddr;
	message recv_message;
	int len;
	//char message[MAXLINE];
	
	bzero(&sockaddr, sizeof(sockaddr));
	sockaddr.sun_family = AF_LOCAL;
	strncpy(sockaddr.sun_path, CUSTOM_SUN_PATH, sizeof(sockaddr.sun_path) - 1);
	
	len = sizeof(struct sockaddr);
	recvfrom(sockfd, &recv_message, sizeof(recv_message), 0, (SA *)&sockaddr, &len);

	//memset(msg_recvd, '\0', 50);
	//strncpy(msg_recvd, mesg.msg, 50);
	//memset(src_addr, '\0', 17);
	//strncpy(src_addr, mesg.src_addr, 17);
	//*src_port = mesg.src_port;
	return(0);

}
